<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript" src="libra.util.js"></script>
<script type="text/javascript" src="libra.controller.js"></script>
<script type="text/javascript" src="libra.model.js"></script>
</head>
<body>
<script type="text/javascript">

var util = 'util' in this ? this['util'] : require('./libra.util');

var Model = util.using('model');
var Controller = util.using('controller');

var m = Model.create(['left', 'top', 'width', 'height'], function(v, key){
	v = v || 0;
	if(isNaN(v)) v = 0;
	if(key == 'width' || key == 'height'){
		v = Math.max(0, v);
	}
	return v;
});

var c = Controller.create(function(target, newVal, oldVal, model, targetId){
	console.log(this.id, newVal, oldVal, model.id, targetId);
});

m.bind(c);
// m.unbind(c)

m.put({
	left: 0, width: 20
});

// function ajax_get(url, onload, onerror){
// 	var xhr = new XMLHttpRequest();
// 	xhr.open('GET', url, true);
// 	xhr.onload = onload;
// 	xhr.onerror = onerror;
// 	xhr.send(null);
// }


</script>
</body>
</html>